package drds.configuration.web.common;

import drds.configuration.configuration.ConfigUtil;
import drds.configuration.db.DataBaseManager;
import drds.tools.$;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.ServletContextEvent;

/**
 * @author caozhenghui@drds.team<330937205@qq.com>
 */
@Slf4j
public class ServletContextListener implements javax.servlet.ServletContextListener {
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        try {
            ConfigUtil.setClassPathOuterBaseClass(ServletContextListener.class);

            String packageName = ServletContextListener.class.getPackage().getName();
            String[] packageNameSplits = packageName.split("\\.");
            String basePackage = packageNameSplits[0] + "." + packageNameSplits[1];//系统要求当前类包名.分割之后前两位


            DataBaseManager.init();

        } catch (Exception e) {
            log.error("初始化失败", $.printStackTraceToString(e));
            throw new RuntimeException(e);
        }

    }

    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }


}
